//
// Created by YXH on 2023/2/21.
//

#ifndef ALGORITHM_SORTTESTHELPER_H
#define ALGORITHM_SORTTESTHELPER_H

#include "iostream"
#include "ctime"
#include "cassert"

using namespace std;

namespace SortTestHelper {
    int *generateRandomArray(int n, int rangeL, int rangeR) {

        assert(rangeL <= rangeR);
        int *array = new int[n];
        srand(time(NULL));

        for (int i = 0; i < n; i++) {
            array[i] = rand() % (rangeR - rangeL + 1) + rangeL;
        }
        return array;
    }

    template<typename T>
    void printArray(T *array, int n) {
        for (int i = 0; i < n; i++) {
            cout << array[i] << " ";
        }
        cout << endl;
        return;
    }

    template<typename T>

    bool isSorted(T *array, int n) {
        for (int i = 1; i < n; i++) {
            if (array[i - 1] > array[i]) {
                return false;
            }
        }
        return true;
    }
    template<typename T>
    void testSort(string SortName, void(*sort)(T[], int), T arr[], int n) {
        cout << "Testing " << SortName << endl;
        clock_t start, end;
        start = clock();
        sort(arr, n);
        end = clock();
        assert(isSorted(arr, n));
        cout  << SortName << " is " << double(end - start) / CLOCKS_PER_SEC << " seconds" << endl;
    }

}
#endif //ALGORITHM_SORTTESTHELPER_H
